/*     */ package com.zimbra.cs.mailclient.smtp;
/*     */ 
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.Log.Level;
/*     */ import com.zimbra.cs.mailclient.MailClient;
/*     */ import com.zimbra.cs.mailclient.MailConfig;
/*     */ import com.zimbra.cs.mailclient.MailConfig.Security;
/*     */ import java.io.PrintStream;
/*     */ import org.apache.commons.cli.CommandLine;
/*     */ import org.apache.commons.cli.CommandLineParser;
/*     */ import org.apache.commons.cli.GnuParser;
/*     */ import org.apache.commons.cli.HelpFormatter;
/*     */ import org.apache.commons.cli.Options;
/*     */ import org.apache.commons.cli.ParseException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class SmtpClient
/*     */   extends MailClient
/*     */ {
/*  35 */   private final Options options = new Options();
/*     */   
/*     */   protected SmtpClient() {
/*  38 */     super(new SmtpConfig());
/*     */     
/*  40 */     this.options.addOption("p", "port", true, "SMTP server port (default is 25 or 465 for SSL)");
/*     */     
/*  42 */     this.options.addOption("u", "user", true, "SMTP-AUTH: username");
/*  43 */     this.options.addOption("w", "password", true, "SMTP-AUTH: password");
/*  44 */     this.options.addOption("r", "realm", true, "SMTP-AUTH: realm");
/*  45 */     this.options.addOption("m", "mechanism", true, "SMTP-AUTH: mechanism (LOGIN|PLAIN|CRAM-MD5|DIGEST-MD5)");
/*  46 */     this.options.addOption("s", "ssl", false, "enable SSL (SMTPS)");
/*  47 */     this.options.addOption("d", "debug", false, "enable debug output");
/*  48 */     this.options.addOption("h", "help", false, "print this help message");
/*     */   }
/*     */   
/*     */   protected void printUsage(PrintStream ps)
/*     */   {
/*  53 */     usage();
/*     */   }
/*     */   
/*     */   private void usage() {
/*  57 */     HelpFormatter help = new HelpFormatter();
/*  58 */     help.setWidth(100);
/*  59 */     help.printHelp("zmjava " + getClass().getName() + " [OPTIONS] [HOSTNAME]", this.options);
/*     */   }
/*     */   
/*     */   protected void parseArguments(String[] args, MailConfig config)
/*     */   {
/*  64 */     CommandLineParser parser = new GnuParser();
/*  65 */     CommandLine cl = null;
/*     */     try {
/*  67 */       cl = parser.parse(this.options, args);
/*     */     } catch (ParseException e) {
/*  69 */       System.err.println(e.getMessage());
/*  70 */       System.exit(1);
/*     */     }
/*     */     
/*  73 */     if (cl.hasOption('p')) {
/*  74 */       config.setPort(Integer.parseInt(cl.getOptionValue('p')));
/*     */     } else {
/*  76 */       config.setPort(25);
/*     */     }
/*  78 */     if (cl.hasOption('m')) {
/*  79 */       config.setMechanism(cl.getOptionValue('m').toUpperCase());
/*     */     }
/*  81 */     if (cl.hasOption('u')) {
/*  82 */       config.setAuthenticationId(cl.getOptionValue('u'));
/*     */     }
/*  84 */     if (cl.hasOption('w')) {
/*  85 */       setPassword(cl.getOptionValue('w'));
/*     */     }
/*  87 */     if (cl.hasOption('r')) {
/*  88 */       config.setRealm(cl.getOptionValue('r'));
/*     */     }
/*  90 */     if (cl.hasOption('s')) {
/*  91 */       config.setSecurity(MailConfig.Security.SSL);
/*     */     }
/*  93 */     if (cl.hasOption('d')) {
/*  94 */       config.getLogger().setLevel(Log.Level.trace);
/*     */     }
/*  96 */     if (cl.hasOption('h')) {
/*  97 */       usage();
/*  98 */       System.exit(0);
/*     */     }
/*     */     
/* 101 */     String[] remaining = cl.getArgs();
/* 102 */     config.setHost(remaining.length > 0 ? remaining[0] : "localhost");
/*     */   }
/*     */   
/*     */   public static void main(String[] args) throws Exception {
/* 106 */     new SmtpClient().run(args);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailclient/smtp/SmtpClient.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */